var orderCache = require('../../../utils/mr_xu/apply_order_cache.js')
var common = require('../../../utils/mr_xu/common.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    select: 0,
    list: [
      { name: '不可用', value: false },
      { name: '可用', value: true }
    
    ]
  },


  select(e) {
    let index = e.currentTarget.dataset.index
    console.log(index)
    this.setData({
      select: index
    })
  },

  next() {
    let that = this

    common.safeRun(function() {

      let car = orderCache.getItem('car')
      let isGps = that.data.list[that.data.select].value

      if (car && typeof car === 'object')
        car.isGps = isGps

      orderCache.setItem('car', car)

      if (isGps) {
        wx.navigateTo({
          url: '../step4_select_service/select_service?isGps=true',
        })
      } else {
        wx.navigateTo({
          url: '../step4_select_service/select_service?isGps=false',
        })
      }
    })
    
  },
  onLoad() {

    console.log('type')
    console.log(orderCache.getItem('type'))
    
    let that = this
    let updateInfo = orderCache.getUpdateInfo()
    if (updateInfo) {
      let items = that.data.list
      let index = 0
      for (let i in items) {
        if (items[i].value == updateInfo.car.isGps) {
          index = i
          break
        }
      }
      that.setData({
        select: index
      })
    }
  }

})